
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;






class decrypt {


    public static void main(String[] args)
    {
         try{
         System.out.println("Decrypting: Key["+args[0]+"]  Inputfile:["+args[1]+"] Outputfile:["+args[2]+"]");
           decryptfile(args[0],args[1],args[2]);
         } catch (Exception ex){
         System.out.println("usage  Key  Inputfile  Outputfile");
            System.out.println("Error:"+ex.toString());

         }
    }

    // public decrypt() {

    //     System.out("Decrypting: Key["+args[0]+"]  Inputfile:["+args[1]+"] Outputfile:["+args[2]+"]");
    //     decryptfile(args[0],args[1],args[2]);
    // }

    public static void decryptfile(String key, String ifile, String ofile) throws IOException, NoSuchAlgorithmException,
            NoSuchPaddingException, InvalidKeyException {
        FileInputStream fis = new FileInputStream(ifile);

        FileOutputStream fos = new FileOutputStream(ofile);
        SecretKeySpec sks = new SecretKeySpec(key.getBytes(),
                "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, sks);
        CipherInputStream cis = new CipherInputStream(fis, cipher);
        int b;
        byte[] d = new byte[8];
        while ((b = cis.read(d)) != -1) {
            fos.write(d, 0, b);
        }
        fos.flush();
        fos.close();
        cis.close();
    }


}

